package com.fr.report.io;

import com.fr.base.BaseUtils;
import com.fr.base.ColumnRow;
import com.fr.base.FRFont;
import com.fr.base.Painter;
import com.fr.base.StringUtils;
import com.fr.base.Style;
import com.fr.base.background.Background;
import com.fr.base.background.ColorBackground;
import com.fr.base.background.PatternBackground;
import com.fr.base.core.GraphHelper;
import com.fr.chart.ChartCollection;
import com.fr.chart.ChartPainter;
import com.fr.data.core.db.BinaryObject;
import com.fr.report.CellElement;
import com.fr.report.DefaultCellElement;
import com.fr.report.FloatElement;
import com.fr.report.Margin;
import com.fr.report.PaperSetting;
import com.fr.report.PaperSize;
import com.fr.report.RWorkSheet;
import com.fr.report.Report;
import com.fr.report.ReportHF;
import com.fr.report.ReportPageAttr;
import com.fr.report.ReportSettings;
import com.fr.report.ResultReport;
import com.fr.report.ResultWorkBook;
import com.fr.report.cellElement.CellGUIAttr;
import com.fr.report.cellElement.CellPageAttr;
import com.fr.report.cellElement.Formula;
import com.fr.report.cellElement.core.CellElementAttribute;
import com.fr.report.core.DynamicValueList;
import com.fr.report.core.PackedReport;
import com.fr.report.core.PaintUtils;
import com.fr.report.core.ReportHelper;
import com.fr.report.core.ReportUtils;
import com.fr.report.core.headerfooter.DateHFElement;
import com.fr.report.core.headerfooter.HFElement;
import com.fr.report.core.headerfooter.NewLineHFElement;
import com.fr.report.core.headerfooter.NumberOfPageHFElement;
import com.fr.report.core.headerfooter.PageNumberHFElement;
import com.fr.report.core.headerfooter.TextHFElement;
import com.fr.report.core.headerfooter.TimeHFElement;
import com.fr.report.io.core.ExcelExporterReport;
import com.fr.report.painter.shape.LineShapePainter;
import com.fr.report.painter.shape.OvalShapePainter;
import com.fr.report.painter.shape.ShapePainter;
import com.fr.third.org.apache.poi.hssf.usermodel.EscherGraphics;
import com.fr.third.org.apache.poi.hssf.usermodel.EscherGraphics2d;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFCell;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFCellStyle;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFDataFormat;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFFont;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFFooter;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFHeader;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFPalette;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFPatriarch;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFPrintSetup;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFRichTextString;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFRow;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFShapeGroup;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFSheet;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFTextbox;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFWorkbook;
import com.fr.third.org.apache.poi.hssf.util.HSSFColor;
import com.fr.third.org.apache.poi.hssf.util.Region;
import com.fr.util.Utils;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Clob;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageIO;

public class ExcelExporter extends AbstractAppExporter
{
  public static final String TYPE_SIMPLE = "simple";
  public static final String TYPE_PAGE = "page";
  public static final String TYPE_PAGETOSHETT = "sheet";
  public static final String TYPE_LARGEDATA_PAGE = "ldpage";
  private HSSFCellStyle defaultHSSFCellStyle;
  private Hashtable hssfFontHash;
  private Hashtable hssfCellStyleHash;
  private HSSFDataFormat format;
  private short colorIndex;
  public static int EXCELCOLS = 256;
  public static int EXCELROWS = 65536;
  protected List paperSettingList;

  public ExcelExporter()
  {
    this(null);
  }

  public ExcelExporter(List paramList)
  {
    this.defaultHSSFCellStyle = null;
    this.hssfFontHash = new Hashtable();
    this.hssfCellStyleHash = new Hashtable();
    this.format = null;
    this.colorIndex = 8;
    this.paperSettingList = null;
    this.paperSettingList = paramList;
  }

  public void export(OutputStream paramOutputStream, ResultWorkBook paramResultWorkBook)
    throws Exception
  {
    export(paramOutputStream, paramResultWorkBook, false);
  }

  public void export(OutputStream paramOutputStream, ResultWorkBook paramResultWorkBook, boolean paramBoolean)
    throws Exception
  {
    int i;
    if (paramResultWorkBook == null)
      throw new Exception("Report can not be null!");
    ArrayList localArrayList1 = new ArrayList();
    this.defaultHSSFCellStyle = null;
    this.hssfFontHash.clear();
    this.hssfCellStyleHash.clear();
    this.format = null;
    this.colorIndex = 8;
    HSSFWorkbook localHSSFWorkbook = new HSSFWorkbook();
    ArrayList localArrayList2 = new ArrayList();
    ArrayList localArrayList3 = new ArrayList();
    exportBook(paramResultWorkBook, localHSSFWorkbook, localArrayList2, localArrayList3, localArrayList1, paramBoolean);
    if (localArrayList2.size() > 0)
      for (i = 0; i < localArrayList2.size(); ++i)
      {
        localObject = (HSSFCell)localArrayList2.get(i);
        String str2 = (String)localArrayList3.get(i);
        try
        {
          ((HSSFCell)localObject).setCellType(2);
          ((HSSFCell)localObject).setCellFormula(str2);
          if ((!(str2.equalsIgnoreCase(((HSSFCell)localObject).getCellFormula()))) && (!(str2.matches(".+![\\w&&[\\D]]+\\d+.*"))))
          {
            ((HSSFCell)localObject).setCellType(1);
            ((HSSFCell)localObject).setCellValue(new HSSFRichTextString("=" + str2));
          }
        }
        catch (Exception localException)
        {
          ((HSSFCell)localObject).setCellType(1);
          ((HSSFCell)localObject).setCellValue(new HSSFRichTextString("=" + str2));
        }
      }
    String str1 = null;
    Object localObject = paramResultWorkBook.getReportExportAttr();
    if ((localObject != null) && (((ReportExportAttr)localObject).getExcelExportAttr() != null))
      str1 = ((ReportExportAttr)localObject).getExcelExportAttr().getPassword();
    if (StringUtils.isNotBlank(str1))
      localHSSFWorkbook.setFilePassword(str1);
    localHSSFWorkbook.write(paramOutputStream);
    paramOutputStream.flush();
  }

  protected void exportBook(ResultWorkBook paramResultWorkBook, HSSFWorkbook paramHSSFWorkbook, List paramList1, List paramList2, List paramList3, boolean paramBoolean)
    throws Exception
  {
    Object localObject1;
    for (int i = 0; i < paramResultWorkBook.getReportCount(); ++i)
    {
      localObject1 = paramResultWorkBook.getReport(i);
      paramList3.add(localObject1);
      while (localObject1 instanceof PackedReport)
      {
        localObject1 = ((PackedReport)localObject1).getPackee();
        paramList3.set(i, localObject1);
      }
    }
    for (i = 0; i < paramResultWorkBook.getReportCount(); ++i)
    {
      localObject1 = (ResultReport)paramList3.get(i);
      if (!(((ResultReport)localObject1).cellIterator().hasNext()))
      {
        localObject2 = new RWorkSheet();
        Iterator localIterator = ((ResultReport)localObject1).floatIterator();
        while (localIterator.hasNext())
          ((ResultReport)localObject2).addFloatElement((FloatElement)localIterator.next());
        localObject1 = localObject2;
        ((ResultReport)localObject1).addCellElement(new DefaultCellElement(0, 0, ""));
      }
      Object localObject2 = new Point(0, 0);
      int j = ((ResultReport)localObject1).getColumnCount();
      int k = ((ResultReport)localObject1).getRowCount();
      int l = 1;
      while (((Point)localObject2).x < j)
      {
        ((Point)localObject2).y = 0;
        while (((Point)localObject2).y < k)
        {
          innerExportReport(new ExcelExporterReport((ResultReport)localObject1, ((Point)localObject2).x, ((Point)localObject2).y, Math.min(j - ((Point)localObject2).x, EXCELCOLS), Math.min(k - ((Point)localObject2).y, EXCELROWS)), paramResultWorkBook.getReportExportAttr(), paramResultWorkBook.getReportName(i) + ((l == 1) ? "" : new StringBuffer().append("_").append(l).toString()), paramHSSFWorkbook, paramList1, paramList2, i);
          localObject2.y += EXCELROWS;
          ++l;
        }
        localObject2.x += EXCELCOLS;
      }
    }
  }

  protected void innerExportReport(Report paramReport, ReportExportAttr paramReportExportAttr, String paramString, HSSFWorkbook paramHSSFWorkbook, List paramList1, List paramList2, int paramInt)
    throws Exception
  {
    ExcelExportAttr localExcelExportAttr = (paramReportExportAttr == null) ? null : paramReportExportAttr.getExcelExportAttr();
    HSSFSheet localHSSFSheet = paramHSSFWorkbook.createSheet();
    if ((localExcelExportAttr != null) && (StringUtils.isNotEmpty(localExcelExportAttr.getProtectedWord())))
      localHSSFSheet.protectSheet(localExcelExportAttr.getProtectedWord());
    setSheetName(paramHSSFWorkbook, paramString);
    iterateReport(paramReport, localHSSFSheet, paramHSSFWorkbook, paramList1, paramList2, localExcelExportAttr, paramInt);
  }

  private void setSheetName(HSSFWorkbook paramHSSFWorkbook, String paramString)
  {
    for (int i = 1; paramHSSFWorkbook.getSheet(paramString) != null; ++i)
      paramString = paramString + "_" + i;
    paramHSSFWorkbook.setSheetName(paramHSSFWorkbook.getNumberOfSheets() - 1, paramString);
  }

  private void iterateReport(Report paramReport, HSSFSheet paramHSSFSheet, HSSFWorkbook paramHSSFWorkbook, List paramList1, List paramList2, ExcelExportAttr paramExcelExportAttr, int paramInt)
    throws Exception
  {
    int i3;
    int i5;
    int i7;
    Object localObject5;
    Object localObject10;
    Object localObject11;
    ReportSettings localReportSettings = ReportUtils.getReportSettings(paramReport);
    paramHSSFSheet.setDefaultColumnWidth(9);
    paramHSSFSheet.setHorizontallyCenter(localReportSettings.isHorizontalCenterOnPage());
    paramHSSFSheet.setVerticallyCenter(localReportSettings.isVerticalCenterOnPage());
    HSSFPrintSetup localHSSFPrintSetup = paramHSSFSheet.getPrintSetup();
    PaperSize localPaperSize = null;
    Margin localMargin = null;
    int i = -1;
    if ((this.paperSettingList != null) && (this.paperSettingList.size() > paramInt))
    {
      localObject1 = (PaperSetting)this.paperSettingList.get(paramInt);
      if (localObject1 != null)
      {
        localPaperSize = ((PaperSetting)localObject1).getPaperSize();
        localMargin = ((PaperSetting)localObject1).getMargin();
        i = ((PaperSetting)localObject1).getOrientation();
      }
    }
    if (localPaperSize == null)
      localPaperSize = localReportSettings.getPaperSize();
    if (localMargin == null)
      localMargin = localReportSettings.getMargin();
    if (i == -1)
      i = localReportSettings.getOrientation();
    if (localPaperSize.equals(PaperSize.PAPERSIZE_LETTER))
      localHSSFPrintSetup.setPaperSize(5);
    else if (localPaperSize.equals(PaperSize.PAPERSIZE_HALFLETTER))
      localHSSFPrintSetup.setPaperSize(2);
    else if (localPaperSize.equals(PaperSize.PAPERSIZE_TABLOID))
      localHSSFPrintSetup.setPaperSize(3);
    else if (localPaperSize.equals(PaperSize.PAPERSIZE_LEDGER))
      localHSSFPrintSetup.setPaperSize(4);
    else if (localPaperSize.equals(PaperSize.PAPERSIZE_LEGAL))
      localHSSFPrintSetup.setPaperSize(5);
    else if (localPaperSize.equals(PaperSize.PAPERSIZE_A3))
      localHSSFPrintSetup.setPaperSize(8);
    else if (localPaperSize.equals(PaperSize.PAPERSIZE_A4))
      localHSSFPrintSetup.setPaperSize(9);
    else if (localPaperSize.equals(PaperSize.PAPERSIZE_A5))
      localHSSFPrintSetup.setPaperSize(11);
    else if (localPaperSize.equals(PaperSize.PAPERSIZE_A6))
      localHSSFPrintSetup.setPaperSize(70);
    else if (localPaperSize.equals(PaperSize.PAPERSIZE_B4))
      localHSSFPrintSetup.setPaperSize(12);
    else if (localPaperSize.equals(PaperSize.PAPERSIZE_B5_JIS))
      localHSSFPrintSetup.setPaperSize(13);
    else if (localPaperSize.equals(PaperSize.PAPERSIZE_NOTE))
      localHSSFPrintSetup.setPaperSize(18);
    else
      localHSSFPrintSetup.setPaperSize(9);
    if (i == 1)
      localHSSFPrintSetup.setLandscape(true);
    else
      localHSSFPrintSetup.setLandscape(false);
    if (localReportSettings.getPageOrder() == 1)
      localHSSFPrintSetup.setLeftToRight(true);
    else
      localHSSFPrintSetup.setLeftToRight(false);
    paramHSSFSheet.setMargin(2, localMargin.getTop());
    paramHSSFSheet.setMargin(0, localMargin.getLeft());
    paramHSSFSheet.setMargin(3, localMargin.getBottom());
    paramHSSFSheet.setMargin(1, localMargin.getRight());
    localHSSFPrintSetup.setHeaderMargin(localReportSettings.getHeaderHeight());
    localHSSFPrintSetup.setFooterMargin(localReportSettings.getFooterHeight());
    if (localReportSettings.getHeaderHeight() > 0.0D)
      applyReportHFHeader(paramReport.getHeader(0), paramHSSFSheet.getHeader());
    if (localReportSettings.getFooterHeight() > 0.0D)
      applyReportHFFooter(paramReport.getFooter(0), paramHSSFSheet.getFooter());
    if ((paramReport.getReportPageAttr() != null) && (paramReport.getReportPageAttr().getFreezeColumnRow() != null))
    {
      localObject1 = paramReport.getReportPageAttr().getFreezeColumnRow();
      paramHSSFSheet.createFreezePane(((ColumnRow)localObject1).getColumn(), ((ColumnRow)localObject1).getRow());
    }
    Object localObject1 = ReportHelper.getRowHeightList(paramReport);
    DynamicValueList localDynamicValueList = ReportHelper.getColumnWidthList(paramReport);
    int j = -1;
    int k = -1;
    HSSFRow localHSSFRow = null;
    HSSFPatriarch localHSSFPatriarch = paramHSSFSheet.createDrawingPatriarch();
    boolean bool1 = (paramExcelExportAttr == null) ? true : paramExcelExportAttr.isExportHidedRow();
    boolean bool2 = (paramExcelExportAttr == null) ? true : paramExcelExportAttr.isExportHidedColumn();
    Iterator localIterator = paramReport.cellIterator();
    while (true)
    {
      int l;
      int i1;
      int i2;
      do
      {
        Object localObject4;
        while (true)
        {
          if (!(localIterator.hasNext()))
            break label2099;
          localObject2 = (CellElement)localIterator.next();
          l = ((CellElement)localObject2).getColumn();
          i1 = ((CellElement)localObject2).getRow();
          i2 = ((CellElement)localObject2).getColumnSpan();
          i3 = ((CellElement)localObject2).getRowSpan();
          i5 = l + i2 - 1;
          i7 = i1 + i3 - 1;
          if (j < i5)
          {
            for (int i8 = Math.max(0, j); i8 <= i5; ++i8)
              if (localDynamicValueList.get(i8) <= 0)
                paramHSSFSheet.setColumnHidden((short)i8, true);
              else
                paramHSSFSheet.setColumnWidth((short)i8, (short)(int)(localDynamicValueList.get(i8) * 34.741999999999997D));
            j = i5;
          }
          if (k < i7)
          {
            for (int i9 = Math.max(0, k); i9 <= i7; ++i9)
            {
              localObject4 = paramHSSFSheet.createRow(i9);
              if (((DynamicValueList)localObject1).get(i9) <= 0)
                ((HSSFRow)localObject4).setZeroHeight(true);
              else
                ((HSSFRow)localObject4).setHeight((short)(int)(((DynamicValueList)localObject1).get(i9) * 15.207675329298683D));
            }
            k = i7;
          }
          CellPageAttr localCellPageAttr = ((CellElement)localObject2).getCellPageAttr();
          if (localCellPageAttr != null)
          {
            if (localCellPageAttr.isPageBeforeColumn())
              paramHSSFSheet.setColumnBreak((short)(l - 1));
            if ((localCellPageAttr.isPageAfterColumn()) && (i5 < EXCELCOLS - 1))
              paramHSSFSheet.setColumnBreak((short)i5);
            if (localCellPageAttr.isPageBeforeRow())
              paramHSSFSheet.setRowBreak(i1 - 1);
            if ((localCellPageAttr.isPageAfterRow()) && (i7 < EXCELROWS - 1))
              paramHSSFSheet.setRowBreak(i7);
          }
          localObject4 = ((CellElement)localObject2).getCellGUIAttr();
          if (localObject4 == null)
            localObject4 = CellGUIAttr.DEFAULT_CELLGUIATTR;
          if (((CellGUIAttr)localObject4).isPrintContent())
            break;
        }
        Style localStyle = ((CellElement)localObject2).getStyle();
        int i13 = l;
        int i14 = i13;
        int i15 = l + i2;
        while (i14 < i15)
        {
          int i16 = i1;
          int i17 = i16;
          int i18 = i1 + i3;
          while (i17 < i18)
          {
            if ((localHSSFRow == null) || (localHSSFRow.getRowNum() != i17))
              localHSSFRow = paramHSSFSheet.getRow(i17);
            localObject10 = localHSSFRow.createCell((short)i14);
            ((HSSFCell)localObject10).setEncoding(1);
            if ((i14 != i13) || (i17 != i16))
            {
              ((HSSFCell)localObject10).setCellStyle(createHSSFCellStyle(paramHSSFWorkbook, localStyle));
            }
            else if ((bool1) || (paramReport.getRowHeight(i17) != 0))
            {
              Object localObject14;
              if ((!(bool2)) && (paramReport.getColumnWidth(i14) == 0))
                break label2036:
              localObject11 = ((CellElement)localObject2).getValue();
              if (localObject11 == null)
                localObject11 = "";
              if (localObject11 instanceof Formula)
              {
                localObject12 = (Formula)localObject11;
                if ((((Formula)localObject12).isReserveInResult()) || (((Formula)localObject12).getResult() == null))
                {
                  localObject13 = ((Formula)localObject11).getContent();
                  if (localObject13 != null)
                    if (((String)localObject13).startsWith("="))
                    {
                      localObject14 = ((String)localObject13).substring(1);
                      paramList1.add(localObject10);
                      paramList2.add(localObject14);
                    }
                    else
                    {
                      paramList1.add(localObject10);
                      paramList2.add(localObject13);
                    }
                }
                else
                {
                  localObject11 = ((Formula)localObject12).getResult();
                }
              }
              else if (localObject11 instanceof byte[])
              {
                localObject12 = ((CellElement)localObject2).getAttribute(CellElementAttribute.ATT_TYPE);
                if ((localObject12 != null) && ("image".equals((String)localObject12)))
                  localObject11 = ImageIO.read(new ByteArrayInputStream((byte[])localObject11));
              }
              else if (localObject11 instanceof Clob)
              {
                localObject11 = Utils.clob2String((Clob)localObject11);
              }
              else if (localObject11 instanceof BinaryObject)
              {
                localObject12 = (BinaryObject)localObject11;
                if (((CellGUIAttr)localObject4).isShowAsImage())
                {
                  localObject11 = ((BinaryObject)localObject12).getImage();
                }
                else
                {
                  localObject13 = null;
                  if (((BinaryObject)localObject12).getBytes().length >= 5000000)
                    if ((localObject13 = ((BinaryObject)localObject12).getImage()) == null)
                      break label1469;
                  localObject11 = (localObject13 == null) ? ((BinaryObject)localObject12).getValue() : localObject13;
                }
              }
              label1469: Object localObject12 = ((CellElement)localObject2).getStyle();
              Object localObject13 = ((Style)localObject12).getFormat();
              if (localObject11 instanceof Formula)
                break label2019:
              if (localObject11 instanceof Number)
              {
                ((HSSFCell)localObject10).setCellType(0);
                ((HSSFCell)localObject10).setCellValue(((Number)localObject11).doubleValue());
              }
              else if (localObject11 instanceof Boolean)
              {
                ((HSSFCell)localObject10).setCellType(4);
                ((HSSFCell)localObject10).setCellValue(((Boolean)localObject11).booleanValue());
              }
              else if ((localObject11 instanceof String) || (localObject11 instanceof Date))
              {
                localObject14 = PaintUtils.valueToText(localObject11, localStyle.getFormat());
                if ((((String)localObject14).indexOf("$$totalPage_number") > -1) || (((String)localObject14).indexOf("$$page_number") > -1))
                  localObject14 = "";
                localObject14 = replaceNewLineChar((String)localObject14);
                if (localObject14 != null)
                  if (((String)localObject14).startsWith("="))
                  {
                    String str1 = ((String)localObject14).substring(1);
                    paramList1.add(localObject10);
                    paramList2.add(str1);
                  }
                  else if (((String)localObject14).length() > 0)
                  {
                    if (localObject13 instanceof NumberFormat)
                    {
                      try
                      {
                        ((HSSFCell)localObject10).setCellValue(Double.parseDouble((String)localObject14));
                        ((HSSFCell)localObject10).setCellType(0);
                      }
                      catch (NumberFormatException localNumberFormatException1)
                      {
                        ((HSSFCell)localObject10).setCellType(1);
                        ((HSSFCell)localObject10).setCellValue((String)localObject14);
                      }
                    }
                    else
                    {
                      ((HSSFCell)localObject10).setCellType(1);
                      ((HSSFCell)localObject10).setCellValue((String)localObject14);
                    }
                  }
              }
              else if ((localObject11 instanceof Painter) || (localObject11 instanceof Image))
              {
                if (localObject11 instanceof ChartCollection);
                localObject14 = new HSSFClientAnchor(0, 0, 0, 0, (short)l, i1, (short)(l + i2), i1 + i3);
                if (localObject11 != null)
                {
                  ((HSSFClientAnchor)localObject14).setAnchorType(2);
                  int i19 = localDynamicValueList.getRangeValue(l, l + i2);
                  int i20 = ((DynamicValueList)localObject1).getRangeValue(i1, i1 + i3);
                  BufferedImage localBufferedImage = GraphHelper.createBufferedImage(i19 + 1, i20 + 1, 2);
                  Graphics2D localGraphics2D = localBufferedImage.createGraphics();
                  PaintUtils.paintContent(localGraphics2D, localObject11, localStyle, i19, i20);
                  localBufferedImage.flush();
                  localGraphics2D.dispose();
                  localHSSFPatriarch.createPicture((HSSFClientAnchor)localObject14, loadPicture(localBufferedImage, paramHSSFWorkbook));
                }
              }
              else if (localObject11 != null)
              {
                localObject14 = localObject11.toString();
                if (localObject14 != null)
                  if (((String)localObject14).startsWith("="))
                  {
                    String str2 = ((String)localObject14).substring(1);
                    paramList1.add(localObject10);
                    paramList2.add(str2);
                  }
                  else if (((String)localObject14).length() > 0)
                  {
                    localObject14 = replaceNewLineChar((String)localObject14);
                    if (localObject13 instanceof NumberFormat)
                    {
                      try
                      {
                        ((HSSFCell)localObject10).setCellValue(Double.parseDouble((String)localObject14));
                        ((HSSFCell)localObject10).setCellType(0);
                      }
                      catch (NumberFormatException localNumberFormatException2)
                      {
                        ((HSSFCell)localObject10).setCellType(1);
                        ((HSSFCell)localObject10).setCellValue((String)localObject14);
                      }
                    }
                    else
                    {
                      ((HSSFCell)localObject10).setCellType(1);
                      ((HSSFCell)localObject10).setCellValue((String)localObject14);
                    }
                  }
              }
              label2019: ((HSSFCell)localObject10).setCellStyle(createHSSFCellStyle(paramHSSFWorkbook, ((CellElement)localObject2).getStyle()));
            }
            label2036: ++i17;
          }
          ++i14;
        }
      }
      while ((i3 <= 1) && (i2 <= 1));
      localObject5 = new Region(i1, (short)l, i1 + i3 - 1, (short)(l + i2 - 1));
      paramHSSFSheet.addMergedRegion((Region)localObject5);
    }
    label2099: Object localObject2 = paramReport.floatIterator();
    while (true)
    {
      FloatElement localFloatElement;
      Object localObject6;
      do
      {
        Object localObject3;
        label3192: 
        do
          while (true)
          {
            do
            {
              while (true)
              {
                while (true)
                {
                  if (!(((Iterator)localObject2).hasNext()))
                    return;
                  localFloatElement = (FloatElement)((Iterator)localObject2).next();
                  Point[] arrayOfPoint = ReportHelper.calculateLastColumnAndRowOfFloatElement(paramReport, localFloatElement);
                  localObject3 = localFloatElement.getValue();
                  i3 = 0;
                  i5 = 0;
                  i3 = localFloatElement.getLeftDistance();
                  i5 = localFloatElement.getTopDistance();
                  i7 = 0;
                  int i10 = 0;
                  for (int i11 = localFloatElement.getColumn(); (i3 < 0) && (i11 >= 0); --i11)
                  {
                    i3 += localDynamicValueList.get(i11);
                    --i7;
                  }
                  for (i11 = localFloatElement.getColumn(); (i3 > localDynamicValueList.get(i11)) && (i11 <= j); ++i11)
                  {
                    i3 -= localDynamicValueList.get(i11);
                    ++i7;
                  }
                  for (i11 = localFloatElement.getRow(); (i5 < 0) && (i11 >= 0); --i11)
                  {
                    i5 += ((DynamicValueList)localObject1).get(i11);
                    --i10;
                  }
                  for (i11 = localFloatElement.getRow(); (i5 > ((DynamicValueList)localObject1).get(i11)) && (i11 <= k); ++i11)
                  {
                    i5 -= ((DynamicValueList)localObject1).get(i11);
                    ++i10;
                  }
                  int i4 = (int)(new Double(i3).doubleValue() / ((DynamicValueList)localObject1).get(localFloatElement.getRow() + i10) * 1023.0D);
                  int i6 = (int)(new Double(i5).doubleValue() / localDynamicValueList.get(localFloatElement.getColumn() + i7) * 255.0D);
                  i11 = (int)(new Double(arrayOfPoint[1].x).doubleValue() / ((DynamicValueList)localObject1).get((short)arrayOfPoint[0].x) * 1023.0D);
                  int i12 = (int)(new Double(arrayOfPoint[1].y).doubleValue() / localDynamicValueList.get(arrayOfPoint[0].y) * 255.0D);
                  localObject5 = new HSSFClientAnchor(1023, 255, 1023, 255, (short)(localFloatElement.getColumn() + i7), localFloatElement.getRow() + i10, (short)arrayOfPoint[0].x, arrayOfPoint[0].y);
                  if (!(localObject3 instanceof ShapePainter))
                    break;
                  localObject6 = (ShapePainter)localObject3;
                  localObject7 = localFloatElement.getStyle();
                  if (localObject7 == null)
                    localObject7 = Style.DEFAULT_STYLE;
                  localObject8 = localHSSFPatriarch.createGroup((HSSFClientAnchor)localObject5);
                  float f = ((HSSFClientAnchor)localObject5).getAnchorHeightInPoints(paramHSSFSheet) / Math.abs(((HSSFShapeGroup)localObject8).getY2() - ((HSSFShapeGroup)localObject8).getY1());
                  localObject9 = new EscherGraphics((HSSFShapeGroup)localObject8, paramHSSFWorkbook, Color.black, f);
                  localObject10 = new EscherGraphics2d((EscherGraphics)localObject9);
                  ((EscherGraphics2d)localObject10).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                  if (localObject6 instanceof LineShapePainter)
                  {
                    localObject11 = (LineShapePainter)localObject6;
                    ((EscherGraphics2d)localObject10).setPaint(((Style)localObject7).getFRFont().getForeground());
                    if (((LineShapePainter)localObject11).isPositiveArrow())
                      ((EscherGraphics2d)localObject10).drawLine(((HSSFShapeGroup)localObject8).getX1(), ((HSSFShapeGroup)localObject8).getY2(), ((HSSFShapeGroup)localObject8).getX2(), ((HSSFShapeGroup)localObject8).getY1());
                    else
                      ((EscherGraphics2d)localObject10).drawLine(((HSSFShapeGroup)localObject8).getX1(), ((HSSFShapeGroup)localObject8).getY1(), ((HSSFShapeGroup)localObject8).getX2(), ((HSSFShapeGroup)localObject8).getY2());
                  }
                  else if (localObject6 instanceof OvalShapePainter)
                  {
                    applyBackgroundToGraphic2d((EscherGraphics2d)localObject10, ((Style)localObject7).getBackground());
                    ((EscherGraphics2d)localObject10).fillOval(((HSSFShapeGroup)localObject8).getX1(), ((HSSFShapeGroup)localObject8).getY1(), ((HSSFShapeGroup)localObject8).getX2() - ((HSSFShapeGroup)localObject8).getX1(), ((HSSFShapeGroup)localObject8).getY2() - ((HSSFShapeGroup)localObject8).getY1());
                    ((EscherGraphics2d)localObject10).setPaint(((Style)localObject7).getFRFont().getForeground());
                    ((EscherGraphics2d)localObject10).drawOval(((HSSFShapeGroup)localObject8).getX1(), ((HSSFShapeGroup)localObject8).getY1(), ((HSSFShapeGroup)localObject8).getX2() - ((HSSFShapeGroup)localObject8).getX1(), ((HSSFShapeGroup)localObject8).getY2() - ((HSSFShapeGroup)localObject8).getY1());
                  }
                  else
                  {
                    applyBackgroundToGraphic2d((EscherGraphics2d)localObject10, ((Style)localObject7).getBackground());
                    ((EscherGraphics2d)localObject10).fillRect(((HSSFShapeGroup)localObject8).getX1(), ((HSSFShapeGroup)localObject8).getY1(), ((HSSFShapeGroup)localObject8).getX2() - ((HSSFShapeGroup)localObject8).getX1(), ((HSSFShapeGroup)localObject8).getY2() - ((HSSFShapeGroup)localObject8).getY1());
                    ((EscherGraphics2d)localObject10).setPaint(((Style)localObject7).getFRFont().getForeground());
                    ((EscherGraphics2d)localObject10).drawRect(((HSSFShapeGroup)localObject8).getX1(), ((HSSFShapeGroup)localObject8).getY1(), ((HSSFShapeGroup)localObject8).getX2() - ((HSSFShapeGroup)localObject8).getX1(), ((HSSFShapeGroup)localObject8).getY2() - ((HSSFShapeGroup)localObject8).getY1());
                  }
                  ((EscherGraphics2d)localObject10).dispose();
                }
                if ((!(localObject3 instanceof String)) && (!(localObject3 instanceof Number)))
                  break;
                localObject6 = localObject3.toString();
                localObject7 = localFloatElement.getStyle();
                if (localObject7 == null)
                  localObject7 = Style.DEFAULT_STYLE;
                localObject8 = localHSSFPatriarch.createTextbox((HSSFClientAnchor)localObject5);
                Color localColor = Color.white;
                Object localObject9 = ((Style)localObject7).getBackground();
                if ((localObject9 != null) && (localObject9 instanceof ColorBackground))
                  localColor = ((ColorBackground)localObject9).getColor();
                ((HSSFTextbox)localObject8).setFillColor(localColor.getRed(), localColor.getGreen(), localColor.getBlue());
                localObject10 = new HSSFRichTextString((String)localObject6);
                ((HSSFRichTextString)localObject10).applyFont(createHSFFFont(paramHSSFWorkbook, ((Style)localObject7).getFRFont()));
                ((HSSFTextbox)localObject8).setString((HSSFRichTextString)localObject10);
              }
              if (!(localObject3 instanceof Image))
                break label3192;
              localObject6 = (Image)localObject3;
            }
            while (localObject6 == null);
            ((HSSFClientAnchor)localObject5).setAnchorType(2);
            localHSSFPatriarch.createPicture((HSSFClientAnchor)localObject5, loadPicture(GraphHelper.createBufferedImageFromImage((Image)localObject6), paramHSSFWorkbook));
          }
        while (!(localObject3 instanceof ChartPainter));
        localObject6 = (ChartPainter)localObject3;
      }
      while (localObject6 == null);
      ((HSSFClientAnchor)localObject5).setAnchorType(2);
      Object localObject7 = localFloatElement.getSize();
      Object localObject8 = (BufferedImage)((ChartPainter)localObject6).paint4Float(localFloatElement, ((ChartPainter)localObject6).getGlyph(((ChartPainter)localObject6).getSelectedIndex()), (int)((Dimension2D)localObject7).getWidth(), (int)((Dimension2D)localObject7).getHeight());
      localHSSFPatriarch.createPicture((HSSFClientAnchor)localObject5, loadPicture((BufferedImage)localObject8, paramHSSFWorkbook));
    }
  }

  public short getNearestColor(HSSFWorkbook paramHSSFWorkbook, Color paramColor)
  {
    if (paramColor == null)
      paramColor = Color.WHITE;
    HSSFPalette localHSSFPalette = paramHSSFWorkbook.getCustomPalette();
    HSSFColor localHSSFColor = localHSSFPalette.findColor((byte)paramColor.getRed(), (byte)paramColor.getGreen(), (byte)paramColor.getBlue());
    if ((localHSSFColor == null) || (localHSSFColor.getIndex() > this.colorIndex))
    {
      ExcelExporter tmp52_51 = this;
      tmp52_51.colorIndex = (short)(tmp52_51.colorIndex + 1);
      localHSSFPalette.setColorAtIndex(this.colorIndex, (byte)paramColor.getRed(), (byte)paramColor.getGreen(), (byte)paramColor.getBlue());
      localHSSFColor = localHSSFPalette.findColor((byte)paramColor.getRed(), (byte)paramColor.getGreen(), (byte)paramColor.getBlue());
    }
    return localHSSFColor.getIndex();
  }

  private void applyReportHFHeader(ReportHF paramReportHF, HSSFHeader paramHSSFHeader)
  {
    paramHSSFHeader.setLeft(createHFString(paramReportHF.getLeftList(), HSSFHeader.date(), HSSFHeader.time(), HSSFHeader.page(), HSSFHeader.numPages()));
    paramHSSFHeader.setCenter(createHFString(paramReportHF.getCenterList(), HSSFHeader.date(), HSSFHeader.time(), HSSFHeader.page(), HSSFHeader.numPages()));
    paramHSSFHeader.setRight(createHFString(paramReportHF.getRightList(), HSSFHeader.date(), HSSFHeader.time(), HSSFHeader.page(), HSSFHeader.numPages()));
  }

  private void applyReportHFFooter(ReportHF paramReportHF, HSSFFooter paramHSSFFooter)
  {
    paramHSSFFooter.setLeft(createHFString(paramReportHF.getLeftList(), HSSFFooter.date(), HSSFFooter.time(), HSSFFooter.page(), HSSFFooter.numPages()));
    paramHSSFFooter.setCenter(createHFString(paramReportHF.getCenterList(), HSSFFooter.date(), HSSFFooter.time(), HSSFFooter.page(), HSSFFooter.numPages()));
    paramHSSFFooter.setRight(createHFString(paramReportHF.getRightList(), HSSFFooter.date(), HSSFFooter.time(), HSSFFooter.page(), HSSFFooter.numPages()));
  }

  private String createHFString(List paramList, String paramString1, String paramString2, String paramString3, String paramString4)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    for (int i = 0; i < paramList.size(); ++i)
    {
      HFElement localHFElement = (HFElement)paramList.get(i);
      if (localHFElement instanceof TextHFElement)
      {
        FRFont localFRFont = ((TextHFElement)localHFElement).getFRFont();
        String str = "";
        if (localFRFont.getStyle() == 0)
          str = "Plain";
        else if (localFRFont.getStyle() == 1)
          str = "Bold";
        else if (localFRFont.getStyle() == 2)
          str = "Italic";
        else if (localFRFont.getStyle() == 3)
          str = "Bold Italic";
        localStringBuffer.append(HSSFHeader.font(localFRFont.getName(), str));
        localStringBuffer.append(HSSFHeader.fontSize((short)localFRFont.getSize()));
        localStringBuffer.append(" ");
        if (localHFElement.getClass().equals(TextHFElement.class))
          localStringBuffer.append(((TextHFElement)localHFElement).getText());
        else if (localHFElement.getClass().equals(DateHFElement.class))
          localStringBuffer.append(paramString1);
        else if (localHFElement.getClass().equals(TimeHFElement.class))
          localStringBuffer.append(paramString2);
        else if (localHFElement.getClass().equals(PageNumberHFElement.class))
          localStringBuffer.append(paramString3);
        else if (localHFElement.getClass().equals(NumberOfPageHFElement.class))
          localStringBuffer.append(paramString4);
        else if (localHFElement.getClass().equals(NewLineHFElement.class));
      }
    }
    return localStringBuffer.toString();
  }

  private HSSFCellStyle createHSSFCellStyle(HSSFWorkbook paramHSSFWorkbook, Style paramStyle)
  {
    Object localObject;
    if (paramStyle == null)
    {
      if (this.defaultHSSFCellStyle == null)
      {
        this.defaultHSSFCellStyle = paramHSSFWorkbook.createCellStyle();
        executeHSSFCellStyle(paramHSSFWorkbook, this.defaultHSSFCellStyle, Style.DEFAULT_STYLE);
      }
      return this.defaultHSSFCellStyle;
    }
    HSSFCellStyle localHSSFCellStyle = null;
    Enumeration localEnumeration = this.hssfCellStyleHash.keys();
    do
    {
      if (!(localEnumeration.hasMoreElements()))
        break label91;
      localObject = localEnumeration.nextElement();
    }
    while (!(paramStyle.equals(localObject)));
    localHSSFCellStyle = (HSSFCellStyle)this.hssfCellStyleHash.get(localObject);
    if (localHSSFCellStyle == null)
    {
      label91: localHSSFCellStyle = paramHSSFWorkbook.createCellStyle();
      executeHSSFCellStyle(paramHSSFWorkbook, localHSSFCellStyle, paramStyle);
      this.hssfCellStyleHash.put(paramStyle, localHSSFCellStyle);
    }
    return localHSSFCellStyle;
  }

  private void executeHSSFCellStyle(HSSFWorkbook paramHSSFWorkbook, HSSFCellStyle paramHSSFCellStyle, Style paramStyle)
  {
    Format localFormat = paramStyle.getFormat();
    if (localFormat != null)
      if (localFormat instanceof DecimalFormat)
      {
        localObject1 = ((DecimalFormat)localFormat).toPattern();
        paramHSSFCellStyle.setDataFormat(getHSSFDataFormat(paramHSSFWorkbook).getFormat((String)localObject1));
      }
      else if (localFormat instanceof SimpleDateFormat)
      {
        paramHSSFCellStyle.setDataFormat(getHSSFDataFormat(paramHSSFWorkbook).getFormat(((SimpleDateFormat)localFormat).toPattern()));
      }
    Object localObject1 = createHSFFFont(paramHSSFWorkbook, paramStyle.getFRFont());
    if (localObject1 != null)
      paramHSSFCellStyle.setFont((HSSFFont)localObject1);
    paramHSSFCellStyle.setBorderTop(getMapHSSFBorder(paramStyle.getBorderTop()));
    paramHSSFCellStyle.setTopBorderColor(getNearestColor(paramHSSFWorkbook, paramStyle.getBorderTopColor()));
    paramHSSFCellStyle.setBorderLeft(getMapHSSFBorder(paramStyle.getBorderLeft()));
    paramHSSFCellStyle.setLeftBorderColor(getNearestColor(paramHSSFWorkbook, paramStyle.getBorderLeftColor()));
    paramHSSFCellStyle.setBorderBottom(getMapHSSFBorder(paramStyle.getBorderBottom()));
    paramHSSFCellStyle.setBottomBorderColor(getNearestColor(paramHSSFWorkbook, paramStyle.getBorderBottomColor()));
    paramHSSFCellStyle.setBorderRight(getMapHSSFBorder(paramStyle.getBorderRight()));
    paramHSSFCellStyle.setRightBorderColor(getNearestColor(paramHSSFWorkbook, paramStyle.getBorderRightColor()));
    paramHSSFCellStyle.setWrapText(paramStyle.getTextStyle() == 0);
    paramHSSFCellStyle.setRotation((short)paramStyle.getRotation());
    if (paramStyle.getHorizontalAlignment() == 2)
      paramHSSFCellStyle.setAlignment(1);
    else if (paramStyle.getHorizontalAlignment() == 0)
      paramHSSFCellStyle.setAlignment(2);
    else if (paramStyle.getHorizontalAlignment() == 4)
      paramHSSFCellStyle.setAlignment(3);
    if ((paramStyle.getHorizontalAlignment() != 6) || (paramStyle.getVerticalAlignment() == 1))
      paramHSSFCellStyle.setVerticalAlignment(0);
    else if (paramStyle.getVerticalAlignment() == 0)
      paramHSSFCellStyle.setVerticalAlignment(1);
    else if (paramStyle.getVerticalAlignment() == 3)
      paramHSSFCellStyle.setVerticalAlignment(2);
    else if (paramStyle.getVerticalAlignment() == 6);
    Background localBackground = paramStyle.getBackground();
    if (localBackground != null)
    {
      Object localObject2;
      if (localBackground instanceof ColorBackground)
      {
        localObject2 = (ColorBackground)localBackground;
        paramHSSFCellStyle.setFillPattern(1);
        paramHSSFCellStyle.setFillForegroundColor(getNearestColor(paramHSSFWorkbook, ((ColorBackground)localObject2).getColor()));
        paramHSSFCellStyle.setFillBackgroundColor(getNearestColor(paramHSSFWorkbook, ((ColorBackground)localObject2).getColor()));
      }
      else if (localBackground instanceof PatternBackground)
      {
        localObject2 = (PatternBackground)localBackground;
        paramHSSFCellStyle.setFillPattern(16);
        paramHSSFCellStyle.setFillBackgroundColor(getNearestColor(paramHSSFWorkbook, ((PatternBackground)localObject2).getBackground()));
        paramHSSFCellStyle.setFillForegroundColor(getNearestColor(paramHSSFWorkbook, ((PatternBackground)localObject2).getForeground()));
      }
    }
  }

  private HSSFFont createHSFFFont(HSSFWorkbook paramHSSFWorkbook, Font paramFont)
  {
    Object localObject;
    if (paramFont == null)
      return null;
    HSSFFont localHSSFFont = null;
    Enumeration localEnumeration = this.hssfFontHash.keys();
    do
    {
      if (!(localEnumeration.hasMoreElements()))
        break label61;
      localObject = localEnumeration.nextElement();
    }
    while (!(paramFont.equals(localObject)));
    localHSSFFont = (HSSFFont)this.hssfFontHash.get(localObject);
    if (localHSSFFont == null)
    {
      label61: localHSSFFont = paramHSSFWorkbook.createFont();
      this.hssfFontHash.put(paramFont, localHSSFFont);
    }
    localHSSFFont.setFontHeight((short)(paramFont.getSize() * 20 * 3 / 4));
    localHSSFFont.setFontName(paramFont.getName());
    if (paramFont.isBold())
      localHSSFFont.setBoldweight(700);
    else
      localHSSFFont.setBoldweight(400);
    if (paramFont.isItalic())
      localHSSFFont.setItalic(true);
    else
      localHSSFFont.setItalic(false);
    if (paramFont instanceof FRFont)
    {
      localObject = (FRFont)paramFont;
      Color localColor = ((FRFont)localObject).getForeground();
      localHSSFFont.setColor(getNearestColor(paramHSSFWorkbook, localColor));
      if (((FRFont)localObject).isStrikethrough())
        localHSSFFont.setStrikeout(true);
      int i = GraphHelper.getLineStyleSize(((FRFont)localObject).getUnderline());
      if (i == 0)
        localHSSFFont.setUnderline(0);
      else if (i == 1)
        localHSSFFont.setUnderline(1);
      else if (i == 2)
        localHSSFFont.setUnderline(2);
    }
    return ((HSSFFont)localHSSFFont);
  }

  private HSSFDataFormat getHSSFDataFormat(HSSFWorkbook paramHSSFWorkbook)
  {
    if (this.format == null)
      this.format = paramHSSFWorkbook.createDataFormat();
    return this.format;
  }

  private short getMapHSSFBorder(int paramInt)
  {
    if (paramInt == 1)
      return 1;
    if (paramInt == 2)
      return 2;
    if (paramInt == 3)
      return 3;
    if (paramInt == 4)
      return 4;
    if (paramInt == 5)
      return 5;
    if (paramInt == 6)
      return 6;
    if (paramInt == 7)
      return 7;
    if (paramInt == 8)
      return 8;
    if (paramInt == 9)
      return 9;
    if (paramInt == 10)
      return 10;
    if (paramInt == 11)
      return 11;
    if (paramInt == 12)
      return 12;
    if (paramInt == 13)
      return 13;
    return 0;
  }

  private void applyBackgroundToGraphic2d(EscherGraphics2d paramEscherGraphics2d, Background paramBackground)
  {
    if (paramBackground == null)
    {
      paramEscherGraphics2d.setPaint(null);
    }
    else if (paramBackground instanceof ColorBackground)
    {
      ColorBackground localColorBackground = (ColorBackground)paramBackground;
      paramEscherGraphics2d.setPaint(localColorBackground.getColor());
    }
    else
    {
      paramEscherGraphics2d.setPaint(Color.white);
    }
  }

  private int loadPicture(BufferedImage paramBufferedImage, HSSFWorkbook paramHSSFWorkbook)
    throws IOException
  {
    int i;
    ByteArrayOutputStream localByteArrayOutputStream = null;
    try
    {
      localByteArrayOutputStream = new ByteArrayOutputStream();
      BaseUtils.writeImage(paramBufferedImage, "png", localByteArrayOutputStream);
      i = paramHSSFWorkbook.addPicture(localByteArrayOutputStream.toByteArray(), 6);
    }
    finally
    {
      if (localByteArrayOutputStream != null)
      {
        localByteArrayOutputStream.flush();
        localByteArrayOutputStream.close();
      }
    }
    return i;
  }

  private String replaceNewLineChar(String paramString)
  {
    if ((paramString == null) || (paramString.length() <= 0))
      return paramString;
    return paramString.replaceAll("\\\\n", "\n");
  }
}